
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.

# Sets the minimum CMake version required for this project.
# 最低支持的版本
# 注意不代表最终的版本，最终版本在 build.gradle 中设置 最低支持的版本。注意不代表最终的版本，最终版本在 build.gradle 中设置
cmake_minimum_required(VERSION 3.22.1)

# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
# build script scope).
# 当前工程名，以前的旧版本，是没有设置的，这个可以设置，也可以不设置
project("m3u8tool")

# 批量导入源文件
# file 可以定义一个变量 SOURCE， GLOB（使用GLOB从源树中收集源文件列表，就可以开心的 *.cpp *.c *.h）
# https://www.imooc.com/wenda/detail/576408
#file(GLOB SOURCE *.cpp *.c)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
#
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
# is preferred for the same purpose.
#
# In order to load a library into your app from Java/Kotlin, you must call
# System.loadLibrary() and pass the name of the library defined here;
# for GameActivity/NativeActivity derived applications, the same library name must be
# used in the AndroidManifest.xml file.


# 添加一个库（动态库 SHARED，静态库 STATIC）
# 将 SOURCE 表示的源文件进行编译，生成的库
# 的名字是 libffmpeg.so
add_library(libffmpeg
        SHARED
        IMPORTED)

SET_TARGET_PROPERTIES(
        libffmpeg
        PROPERTIES IMPORTED_LOCATION
        ${PROJECT_SOURCE_DIR}/ffmpeg/prebuilt/${ANDROID_ABI}/libffmpeg.so
)

include_directories(ffmpeg/)

add_library(
        ffmpeg-cmd
        SHARED
        ffmpeg/ffmpeg-cmd.cpp ffmpeg/ffmpeg.c ffmpeg/cmdutils.c ffmpeg/ffmpeg_filter.c ffmpeg/ffmpeg_hw.c ffmpeg/ffmpeg_opt.c
)

# 查找 NDK 工具中的动态库 liblog.so 并赋值给变量 log-lib
# 如何知道哪些库可以写呢？通过查看 ndk 中的 system_libs.cmake 文件
find_library( # Sets the name of the path variable.
        log-lib
        log)

# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
# ffmpeg-cmd, libffmpeg是我们编译生成的库 ffmpeg-cmd.so,libffmpeg.so，会被打包进 APK 的 apk/lib/ 目录下，
# 这里将 log-lib 变量所表示的 log 库链接到 libtool 中，也可以直接写 log
target_link_libraries( # Specifies the target library.
        ffmpeg-cmd
        libffmpeg
        ${log-lib})

